/*! 
 * Implementation file for the force registry.
 *
 * \author Devis Rossini
 * \date 18 March 2012
 */ 
#include "PhxForceRegistry.h"

#include <algorithm>

using namespace phx;

void ForceRegistry::Add(RigidBody* body, ForceGenerator* fg)
{
	ForceRegistration registration;
	registration.body = body;
	registration.fg = fg;
	mRegistrations.push_back(registration);
}

void ForceRegistry::Add(const ForceRegistration& fr)
{
	mRegistrations.push_back(fr);
}

//void ForceRegistry::Remove(RigidBody* body, ForceGenerator* fg)
//{
//	ForceRegistration registration;
//	registration.body = body;
//	registration.fg = fg;
//
//	Registry::iterator it = std::find(mRegistrations.begin(), mRegistrations.end(), registration);
//	
//	if (it != mRegistrations.end())
//		mRegistrations.erase(it);
//}

void ForceRegistry::Clear()
{
	mRegistrations.clear();
}

void ForceRegistry::UpdateForces(real duration)
{
	Registry::iterator it = mRegistrations.begin();
	for (; it != mRegistrations.end(); ++it)
	{
		it->fg->UpdateForce(it->body, duration);
	}
}
